const App = {
  mixins: [Query], //配置文件，路径/utils/mixins.js
  data() {
    return {

      currentRow: [],
      showDialogDelete: false,
      showDialogDelete1: false,
      category: [],
      village: [],
      page: {
        value1: "",
        value2: '',
        PageNumber: 1, //页码
        RowAmount: 10,
        Condition: window.btoa(unescape(encodeURIComponent("%%"))),
        //Condition:"",
      },
      deleteReasoninfo: [{ value: "恶意投诉", label: "恶意投诉" }, { value: "不符合事实", label: "不符合事实" },
      { value: "沟通后撤销", label: "沟通后撤销" }, { value: "已解决", label: "已解决" },

      ],
      bdeleted: false,
      Processing_Result: "",
      Feedback_Result: '',
      action_type: '',
      complaint_id: '',
      Rating: '',
      row:{},
      Action_type: [
        // 处理结果
        // { value: "分配", label: "分配" },
        // { value: "处理中", label: "处理中" },
        { value: "已处理", label: "已处理" },
        { value: "拒绝", label: "拒绝" },
      ],
    };
  },
  mounted() {
    // this.Init();
    // this.initWatermark();
  },
  methods: {
    handlexq(row){

      window.location.href = "./add.html?action=Modify&nodeKey=" + row.complaint_id;
    },
    
    handlecl(row) {
      this.complaint_id = row.complaint_id
      this.Processing_Result = ''
      this.action_type = '已处理'
      this.row = row;
      this.showDialogDelete = true;
    },
    handlefk(row) {
      this.complaint_id = row.complaint_id
      this.Feedback_Result = ''
      this.Rating = ''
      this.showDialogDelete1 = true;
    },
    seedMessage(openId, templateId, content) {
      $.ajax({
          headers: requestHeaders('JSON'),
          url: `${mh}/requestForward/requestForwardForPost?RequestURL=${encodeURIComponent(`/wx/mp/sendMicroProgramTemplateMessage`)}`,
          method: "POST",
          data: JSON.stringify({ openId,templateId, content}),
          complete: (XMLHttpRequest) => {
              requestPretreatment(XMLHttpRequest)
          },
      });
  },
    ClickConfirm() {

      if (!this.Processing_Result) {
        this.$message.error("请填写处理结果!");
        return;
      }


      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: 'PatrolComplaints',
          Condition: `complaint_id='${this.complaint_id}'`,
        },
        success: (res) => {
          res[0].Processing_Result = this.Processing_Result;
          res[0].status = this.action_type;
          res[0].Processing_Datetime = getYMDHMSDate();
          let lJSONObject_DataSet = {
            Modify: {
              PatrolComplaints: res
            }
          }
          let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
          lJSONObject_DataSet['Add'] = new Object();
          lJSONObject_DataSet['Add']['base_operation_log'] = [{
            Operation_Type: '0',
            Operation_Path: this.relativePath,
            Operation_Main,
            Operation_Interface: "generalSaveByRequestBody",
            Operation_IP: getIpAddress()
          }]
          submitSave(lJSONObject_DataSet, (res) => {
            if (res.Status == 'success') {
              this.showDialogDelete = false;
              // this.seedMessage(this.row.Open_ID,'RYsotWoL77G3bv7pXVTKGXFPvhrPRA4bhvtiv5eixT4', {
              //   thing1: { value: '线上举报' },
              //   date4: { value: getYMDHMSDate(this.row.Create_Datetime) },
              //   thing2: { value: '已处理' },
              //   thing5: { value: this.Processing_Result }
              // });
              this.postgetList(this.page);
              this.$message({
                type: 'success',
                message: '处理成功'
              });
            } else {
              this.$message({
                type: 'error',
                message: '处理失败'
              });
            }
          })
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest)
        },
      });

    },
    deleteConfirm1() {

      if (!this.Feedback_Result || !this.Rating) {
        this.$message.error("请打分并填写反馈结果!");
        return;
      }

      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
        method: "post",
        data: {
          Data: 'PartyComplaints',
          Condition: `complaint_id='${this.complaint_id}'`,
        },
        success: (res) => {
          res[0].Rating = this.Rating;
          res[0].Feedback_Result = this.Feedback_Result;
          res[0].Feedback_Datetime = getYMDHMSDate();
          let lJSONObject_DataSet = {
            Modify: {
              PartyComplaints: res
            }
          }
          let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
          lJSONObject_DataSet['Add'] = new Object();
          lJSONObject_DataSet['Add']['base_operation_log'] = [{
            Operation_Type: '0',
            Operation_Path: this.relativePath,
            Operation_Main,
            Operation_Interface: "generalSaveByRequestBody",
            Operation_IP: getIpAddress()
          }]
          submitSave(lJSONObject_DataSet, (res) => {
            if (res.Status == 'success') {
              this.showDialogDelete1 = false;
              this.postgetList(this.page);
              this.$message({
                type: 'success',
                message: '反馈成功'
              });
            } else {
              this.$message({
                type: 'error',
                message: '反馈失败'
              });
            }
          })
        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest)
        },
      });
    },
    handleju(data) {
      this.$confirm('该操作将拒绝处理,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
          method: "post",
          data: {
            Data: TableName,
            Condition: primary_key + "='" + data[primary_key] + "'"
          },
          success: (res) => {
            if (res.length == 1) {
              res[0].status = '拒绝';
              res[0].Processing_Datetime = getYMDHMSDate();
              let lJSONObject_DataSet = new Object();
              let lJSONObject_Table = new Object();
              lJSONObject_Table[TableName] = res;
              lJSONObject_DataSet['Modify'] = lJSONObject_Table;
              let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
              lJSONObject_DataSet['Add'] = new Object();
              lJSONObject_DataSet['Add']['base_operation_log'] = [{
                Operation_Type: '0',
                Operation_Path: this.relativePath,
                Operation_Main,
                Operation_Interface: "generalSaveByRequestBody",
                Operation_IP: getIpAddress()
              }]
              submitSave(lJSONObject_DataSet, (res) => {
                if (res.Status == 'success') {
                  this.postgetList(this.page);
                  this.$message({
                    type: 'success',
                    message: '拒绝成功'
                  });
                } else {
                  this.$message({
                    type: 'error',
                    message: '拒绝失败'
                  });
                }
              })
            } else {
              this.showDialogDelete = false;
              this.$message({
                type: 'error',
                message: '拒绝失败'
              });
            }

          },
          complete: (XMLHttpRequest) => {
            requestPretreatment(XMLHttpRequest)
          },
        });
      }).catch(() => { });
    },
    //删除数据
    handleDelete(data) {
      this.$confirm('该操作将删除此条数据,是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {

        let { TableName, primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
        $.ajax({
          headers: requestHeaders(),
          url: `${mh}/generalBusiness/generalQueryByTableNameWithOriginal`,
          method: "post",
          data: {
            Data: TableName,
            Condition: primary_key + "='" + data[primary_key] + "'"
          },
          success: (res) => {
            if (res.length == 1) {
              res[0].Row_Status = '1';
              let lJSONObject_DataSet = new Object();
              let lJSONObject_Table = new Object();
              lJSONObject_Table[TableName] = res;
              lJSONObject_DataSet['Modify'] = lJSONObject_Table;
              let Operation_Main = JSON.stringify(deepClone(lJSONObject_DataSet));
              lJSONObject_DataSet['Add'] = new Object();
              lJSONObject_DataSet['Add']['base_operation_log'] = [{
                Operation_Type: '0',
                Operation_Path: this.relativePath,
                Operation_Main,
                Operation_Interface: "generalSaveByRequestBody",
                Operation_IP: getIpAddress()
              }]
              let _deleteReason = this.deleteReason;
              this.showDialogDelete = false;
              //插入删除日志表记录
              lJSONObject_DataSet['Add']['base_delete_log'] = [{
                TableName: 'complaints',
                KeyName: 'complaint_id',
                KeyValue: data[primary_key],
                Reason: _deleteReason,
                BusinessName: "事件上报"
              }]



              submitSave(lJSONObject_DataSet, (res) => {
                if (res.Status == 'success') {
                  this.postgetList(this.page);
                } else {
                  this.$message({
                    type: 'error',
                    message: '删除失败'
                  });
                }
              })
            } else {
              this.showDialogDelete = false;
              this.$message({
                type: 'error',
                message: '删除失败'
              });
            }

          },
          complete: (XMLHttpRequest) => {
            requestPretreatment(XMLHttpRequest)
          },
        });
      }).catch(() => { });
    },
   
    getUserNameFromCookie() {
      // 从Cookie获取用户名的方法
      return getCookie("user") || "未知用户";
    },
    complaintsAdd() {
      window.location.href = "./add.html?action=Add";
    },
    

    check() {
      //this.page.Condition = window.btoa(unescape(encodeURIComponent(this.page.value1 + ",%"+this.page.value2+"%")));
      console.log("%" + this.page.value1 + "%" );

      this.page.Condition = window.btoa(
        unescape(encodeURIComponent("%" + this.page.value1 + "%"))
      );
      this.postgetList(this.page);
    },
    //树的点击筛选事件
    handleNodeClick(data, node) {
      this.page.Condition = window.btoa(
        unescape(
          encodeURIComponent(
            "%" + this.page.value1 + "%,%" + data.category_id + "%"
          )
        )
      );
      this.postgetList(this.page);
    },
    MemberAdd(row) {
      let str = row["Village_Number"];

      let { primary_key } = JSON.parse(
        document.getElementById("table").getAttribute("data-options")
      );
      window.location.href =
        "./memberAdd.html?action=Modify&nodeKey=" + row[primary_key];
    },
  },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
